package dowork;

import android.os.Bundle;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.sutuijingling.bean.AccountBean;
import com.sutuijingling.bean.h;
import com.sutuijingling.bean.i;
import com.sutuijingling.result.c;
import com.sutuijingling.result.g;
import com.sutuijingling.utils.b;
import java.net.URLEncoder;
import org.apache.http.HttpStatus;

public class SnapshotCreator extends UiAutomatorTestCase {
    static String OUTPUT_LOGIN_SUCCESS = "_tb_login_success_";

    private h fetchOneNotDone() {
        AccountBean accountBean = new AccountBean(true, "要你泥要吐土", "qt3633qt", "");
        h hVar = new h();
        hVar.a(accountBean);
        i iVar = new i();
        iVar.a("杭州市");
        iVar.c("电信");
        iVar.b("183.156.55.233");
        return hVar;
    }

    private boolean isNetflowMatch(h hVar) {
        if (hVar == null) {
            return false;
        }
        try {
            i b = hVar.b();
            b.b(" expected network :" + b, new Object[0]);
            if (b == null) {
                return false;
            }
            String str = (String) new g().c();
            b.b(" remote ip location result :" + str, new Object[0]);
            i d = i.d(str);
            return d == null ? false : b.a(d);
        } catch (Throwable e) {
            b.b(e, e.getMessage(), new Object[0]);
            return false;
        } catch (Throwable e2) {
            b.b(e2, e2.getMessage(), new Object[0]);
            return false;
        }
    }

    public void testCreator() {
        try {
            b.b();
            Bundle params = getParams();
            String encode = URLEncoder.encode(params.getString("name"), "utf-8");
            String encode2 = URLEncoder.encode(params.getString("pswd"), "utf-8");
            b.b(" receive nick :" + encode, new Object[0]);
            b.b(" receive password :" + encode2, new Object[0]);
            h fetchOneNotDone = fetchOneNotDone();
            if (fetchOneNotDone == null) {
                b.c(" no bean for current ", new Object[0]);
            }
            if (!isNetflowMatch(fetchOneNotDone)) {
                b.c(" failed for not ok  network env", new Object[0]);
            }
            com.sutuijingling.a.g gVar = new com.sutuijingling.a.g(getUiDevice());
            gVar.doOpenMyTaobaoScript();
            boolean ensureLogin = gVar.ensureLogin(fetchOneNotDone.a(), false);
            b.b(OUTPUT_LOGIN_SUCCESS + ":" + ensureLogin, new Object[0]);
            if (!ensureLogin) {
                throw new c(HttpStatus.SC_UNAUTHORIZED, "登录失败");
            }
        } catch (Throwable e) {
            b.b(e, e.getMessage(), new Object[0]);
        } catch (Throwable e2) {
            b.b(e2, e2.getMessage(), new Object[0]);
        } catch (Throwable e22) {
            b.b(e22, e22.getMessage(), new Object[0]);
        } finally {
            b.a();
        }
    }
}
